const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin'); //自动生成html文件的插件
const CleanWebpackPlugin = require('clean-webpack-plugin'); //清除之前打包的文件
const ExtractTextPlugin = require("extract-text-webpack-plugin"); //抽离css样式,防止将样式打包在js中引起页面样式加载错乱的现象

module.exports = {
    entry: {
        app: './src/js/entry.js',
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: '[name].[hash].js'
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: ExtractTextPlugin.extract({
                    fallback: "style-loader",
                    use: "css-loader"
                })
            },
            {
                test: /\.json$/,
                use: 'json-loader'
            },
            {
                test: /\.(png|jpg|gif)$/,
                use: [
                    {
                        loader: 'url-loader',
                        options: {
                            limit: 8192
                        }
                    }
                ]
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            filename: "index.html",//默认值为index.html
            template: './index.html',//模板文件
            inject: true //默认值为true，自动注入js/css
        }),
        new CleanWebpackPlugin(),
        new ExtractTextPlugin("test.css"),
    ]


};